(function() {


})()

let swiper = document.querySelector('.swiper');
let itemContainer = document.querySelector('#item-container')
let leftBtn = document.querySelector('.left')
let rightBtn = document.querySelector('.right')
let items = document.querySelectorAll('.item')

//获取swiper的容器宽度
const swiperWidth = parseFloat(getComputedStyle(swiper).width)

//当前轮播图的索引
let index = 0;
let count = items.length
itemContainer.style.width = count * swiperWidth + "px"

function next() {
    index = index == count - 1 ? -1 : index
    itemContainer.style.transform = `translateX(${-swiperWidth*++index}px)`
}

function prev() {
    index = index == 0 ? count : index
    itemContainer.style.transform = `translateX(${-swiperWidth*--index}px)`
}

function moveTo(i) {
    i = i >= count ? count - 1 : i;
    i = i <= 0 ? 0 : i;
    index = i;
    itemContainer.style.transform = `translateX(${-swiperWidth*i}px)`
}